package org.fing.edu.uy.esbadp.motor.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.fing.edu.uy.esbadp.core.AdpFlowInterface;
import org.fing.edu.uy.esbadp.core.entity.GenericTreeNode;

public class RegistryChangeContract {
	
	private static RegistryChangeContract instance;
	
	private Map<Long, GenericTreeNode<AdpFlowInterface>> changeContracts;
	
	private RegistryChangeContract(){
		changeContracts = new ConcurrentHashMap<Long, GenericTreeNode<AdpFlowInterface>>();
	}
	
	public synchronized static RegistryChangeContract getInstance() {
		if(instance == null){
			instance = new RegistryChangeContract();
		}
		return instance;
	}
	
	public void addChange(long serviceId, GenericTreeNode<AdpFlowInterface> node){
		changeContracts.put(serviceId, node);
	}
	
	public GenericTreeNode<AdpFlowInterface> getChangeCopy(long serviceId){
		return changeContracts.get(serviceId).clone();
	}
	
	public boolean existChange(long serviceId){
		return changeContracts.containsKey(serviceId);
	}

}
